package com.example.administrator.mymusic.zhong;

import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.example.administrator.mymusic.Class.MySongsAdapter;
import com.example.administrator.mymusic.Class.SongsClass;
import com.example.administrator.mymusic.MainActivity;
import com.example.administrator.mymusic.MyService;
import com.example.administrator.mymusic.R;
import com.example.administrator.mymusic.XiaFragment;

import java.util.List;

/**
 * Created by Administrator on 2013/1/2.
 */
public class SongsFragment extends Fragment {
    private ListView listView;
    private List<SongsClass> data;
    private XiaFragment xiaFragment;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_zhong_songs, null);
        listView = (ListView) view.findViewById(R.id.lv_fr_zhong_songs);
        MainActivity mainActivity = (MainActivity) getActivity();
        data = mainActivity.getDatas();
        MySongsAdapter myAdapter = new MySongsAdapter(getActivity(), data);
        listView.setAdapter(myAdapter);
        xiaFragment = (XiaFragment) getActivity()
                .getSupportFragmentManager().findFragmentByTag("xiaFragment");
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @TargetApi(Build.VERSION_CODES.KITKAT)
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(getActivity(), MyService.class);
                intent.putExtra("song", position);
                getActivity().startService(intent);

                xiaFragment.getImStart().setBackgroundResource(R.mipmap.pause);
                xiaFragment.getoAnimator().pause();
                xiaFragment.XuanZhuan(0);
                xiaFragment.getoAnimator().start();

            }
        });
        return view;
    }

}
